package edu.biwu.filter;

import jakarta.servlet.*;

import java.io.IOException;

/**
 * 过滤器的创建
 *      1.新建一个类，实现jakarta.sevlet.Filter接口
 *      2.重写doFilter方法
 */

public class FilterDemo01 implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("FilterDemo01开始执行" + request + "..." + response);
        chain.doFilter(request,response); //一旦执行该方法，那么过滤器就会放行，让其访问目标资源
        System.out.println("FilterDemo01结束执行");
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("FilterDemo01的响应");
    }
}
